package com.riddle.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.riddle.model.Article;
import com.riddle.service.ArticleService;
import com.riddle.util.JsonUtil;

@Controller
@RequestMapping("/home")
public class HomeController {

	@Resource
	private ArticleService articleService;
	
	@RequestMapping()
	public String index() {
		return "index";
	}
	
	@RequestMapping(value="/list", produces="application/json;charset=utf-8")
	@ResponseBody
	public String list() {
		List<Article> res = articleService.getArticles();
		return JsonUtil.toJson(res);
	}
	
	@RequestMapping("contact")
	public ModelAndView contact() {
		return new ModelAndView("contact");
	}
}
